/// @tags:
#include <cstdio>
#include <functional>
#include <iostream>
#include <numeric>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

constexpr int maxn = 3e5;

int a[maxn + 1];

void solve() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  int last = 1, start = 2;
  bool inOptSlope;
  for (int i = 1; i <= n; ++i) {
    if (i == n) {
      cout << 1 << endl;
      return;
    }
    if (a[i + 1] != a[i]) {
      start = i + 1;
      inOptSlope = (a[i + 1] > a[i]);
      break;
    }
  }
  int ans = n;
  for (int i = start + 1; i <= n; ++i) {
    if (inOptSlope) {
      if (a[i] >= a[i - 1]) {
      } else {
        ans -= i - last - 1;
        last = i;
        inOptSlope = false;
      }
    } else {
      if (a[i] <= a[i - 1]) {
      } else {
        ans -= i - last - 1;
        last = i;
        inOptSlope = true;
      }
    }
  }
  ans -= n - last - 1;
  cout << ans << endl;
}

int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("C. Contrast Value.in", "r", stdin);
  freopen("C. Contrast Value.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
